#include <amxmodx>
#include <amxmisc>
#include <dprp>

new g_EmployMenu[] = "DPRP_EmployMenu"
new g_FineMenu[] = "DPRP_FineMenu"

new g_Finer[33]
new g_Employer[33]
new g_JobID[33]
new g_Amount[33]

public plugin_init()
{
	new Version[33]
	DPRP_Version(Version,32)
	register_plugin("DeepPurpleRP - Commands",Version,"Hawk552")
	
	register_clcmd("say","CmdSay")
	
	DPRP_AddCommand("say /sell","<price> - puts property for sale for price")
	DPRP_AddCommand("say /addaccess","<user> - gives user access to the door you're looking at")
	DPRP_AddCommand("say /delaccess","<user> - removes user's access from the door you're looking at")
	DPRP_AddCommand("say /changename","<name> - changes the name of the property you're looking at")
	DPRP_AddCommand("say /givemoney","<amount> - gives money to a user from wallet")
	
	DPRP_RegisterCmd("dprp_setmoney","CmdSetMoney","(ADMIN) <user> <money> - sets user's wallet money")
	DPRP_RegisterCmd("dprp_setbank","CmdSetBank","(ADMIN) <user> <money> - sets user's bank money")
	DPRP_RegisterCmd("dprp_additems","CmdAddItems","(ADMIN) <user> <item> <amount> - gives items to user")
	DPRP_RegisterCmd("dprp_setjob","CmdSetJob","(ADMIN) <user> <jobid/jobname> - sets user's job id")
	DPRP_RegisterCmd("dprp_employ","CmdEmploy","(ADMIN) <user> <jobid/jobname> - offers job to user")
	DPRP_RegisterCmd("dprp_addproperty","CmdAddProperty","(ADMIN) <name> <name> <owner> <authid> <price> <lock> <access> <profit>")
	DPRP_RegisterCmd("dprp_adddoor","CmdAddDoor","(ADMIN) <internalname> - hooks a door to a property")
	DPRP_RegisterCmd("dprp_propertyaccess","CmdPropertyAccess","(ADMIN) <access> - sets access level for a property")
	DPRP_RegisterCmd("dprp_setaccess","CmdSetAccess","(ADMIN) <user> <access> - sets user's access")
	DPRP_RegisterCmd("dprp_addjob","CmdAddJob","(ADMIN) <name> <salary> <access> - adds job")
	DPRP_RegisterCmd("dprp_setjobright","CmdSetJobRight","(ADMIN) <name> <rights> - sets user's job rights")
	
	register_menucmd(register_menuid(g_EmployMenu),MENU_KEY_1|MENU_KEY_2,"EmployHandle")
	register_menucmd(register_menuid(g_FineMenu),MENU_KEY_1|MENU_KEY_2,"FineHandle")
}

public DPRP_Error(const Reason[])
	pause("d")

public CmdSetJobRight(id,level,cid)
{
	if(!DPRP_CmdAccess(id,cid,3))
		return PLUGIN_HANDLED
	
	new Arg[33]
	read_argv(1,Arg,32)
	
	new Target = cmd_target(id,Arg,1|2)
	if(!Target)
		return PLUGIN_HANDLED
	
	read_argv(2,Arg,32)
	new Access = DPRP_AccessToInt(Arg)
	
	DPRP_SetUserJobRight(Target,Access)
	
	new Name[33]
	get_user_name(Target,Name,32)
	
	client_print(id,print_console,"You have set %s's job rights to %s",Name,Arg)
	
	return PLUGIN_HANDLED
}

public CmdAddJob(id,level,cid)
{
	if(!DPRP_CmdAccess(id,cid,4))
		return PLUGIN_HANDLED
	
	new Arg[33],AccessStr[JOB_ACCESSES + 1],Results[1]
	
	read_argv(2,Arg,32)
	new Salary = str_to_num(Arg)
	
	read_argv(3,AccessStr,JOB_ACCESSES)
	new Access = DPRP_AccessToInt(AccessStr)
	
	read_argv(1,Arg,32)
	remove_quotes(Arg)
	trim(Arg)
	
	DPRP_FindJobId(Arg,Results,1)
	
	if(Results[0])
	{
		new TempName[33]
		DPRP_GetJobName(Results[0],TempName,32)
		
		client_print(id,print_console,"A similar job is already taken. You entered: %s - Existing job: %s",Arg,TempName)
		return PLUGIN_HANDLED
	}
	
	if(DPRP_AddJob(Arg,Salary,Access))
		client_print(id,print_console,"Job %s to database with salary $%d and access %s.",Arg,Salary,AccessStr)
	
	return PLUGIN_HANDLED
}

public CmdSetAccess(id,level,cid)
{
	if(!DPRP_CmdAccess(id,cid,3))
		return PLUGIN_HANDLED
	
	new Arg[33]
	read_argv(1,Arg,32)
	
	new Target = cmd_target(id,Arg,1|2)
	if(!Target)
		return PLUGIN_HANDLED
	
	read_argv(2,Arg,32)
	new Access = DPRP_AccessToInt(Arg)
	
	DPRP_SetUserAccess(Target,Access)
	
	new Name[33]
	get_user_name(Target,Name,32)
	
	client_print(id,print_console,"You have set %s's access to %s",Name,Arg)
	
	return PLUGIN_HANDLED
}

public CmdPropertyAccess(id,level,cid)
{
	new Index,Body
	get_user_aiming(id,Index,Body,200)
	
	if(!Index || !is_valid_ent(Index))
	{
		client_print(id,print_chat,"[DPRP] You are not looking at a valid door.")
		return PLUGIN_HANDLED
	}
	
	new Classname[33]
	entity_get_string(Index,EV_SZ_classname,Classname,32)
	
	if(containi(Classname,"door") == -1)
	{
		client_print(id,print_chat,"[DPRP] You are not looking at a valid door.")
		return PLUGIN_HANDLED
	}
	
	if(read_argc() != 2)
	{
		new Access[JOB_ACCESSES + 1],Targetname[33]
		entity_get_string(Index,EV_SZ_targetname,Targetname,32)
		
		new Property = DPRP_PropertyMatch(Targetname,Index)
		if(!Property)
			return PLUGIN_HANDLED
		
		DPRP_IntToAccess(DPRP_PropertyGetAccess(Property),Access,JOB_ACCESSES)
		
		client_print(id,print_console,"This property's access flags are ^"%s^".",Access)
		
		return PLUGIN_HANDLED
	}		
	
	if(!DPRP_CmdAccess(id,cid,2))
		return PLUGIN_HANDLED
	
	new Arg[JOB_ACCESSES + 1],Targetname[33]
	read_argv(1,Arg,JOB_ACCESSES)
	
	entity_get_string(Index,EV_SZ_targetname,Targetname,32)
	new Property = DPRP_PropertyMatch(Targetname,Index)
	if(!Property)
		return PLUGIN_HANDLED
	
	new Access = DPRP_AccessToInt(Arg)
	
	DPRP_PropertySetAccess(Property,Access)
	
	//DPRP_AddProperty
	
	client_print(id,print_console,"You have set this property's access to ^"%s^".",Arg)
	
	return PLUGIN_HANDLED
}

public CmdAddProperty(id,level,cid)
{
	if(!DPRP_CmdAccess(id,cid,9))
		return PLUGIN_HANDLED
	
	new InternalName[64],ExternalName[64],OwnerName[33],OwnerAuth[36],Price,Locked,AccessStr[JOB_ACCESSES + 1],Access,Profit,Temp[33]
	read_argv(1,InternalName,63)
	if(DPRP_ValidPropertyName(InternalName))
	{
		client_print(id,print_console,"Property %s already exists.",InternalName)
		return PLUGIN_HANDLED
	}
	
	read_argv(2,ExternalName,63)
	read_argv(3,OwnerName,32)
	read_argv(4,OwnerAuth,35)
	read_argv(5,Temp,32)
	Price = str_to_num(Temp)
	read_argv(6,Temp,32)
	Locked = str_to_num(Temp)
	read_argv(7,AccessStr,JOB_ACCESSES)
	Access = DPRP_AccessToInt(AccessStr)
	read_argv(8,Temp,32)
	Profit = str_to_num(Temp)
	
	remove_quotes(InternalName)
	remove_quotes(ExternalName)
	remove_quotes(OwnerName)
	remove_quotes(OwnerAuth)
	trim(InternalName)
	trim(ExternalName)
	trim(OwnerName)
	trim(OwnerAuth)
	
	DPRP_AddProperty(InternalName,ExternalName,OwnerName,OwnerAuth,Price,Locked,Access,Profit)
	
	return PLUGIN_HANDLED
}

public CmdAddDoor(id,level,cid)
{
	if(!DPRP_CmdAccess(id,cid,2))
		return PLUGIN_HANDLED
		
	new Index,Body
	get_user_aiming(id,Index,Body,200)
	
	if(!Index || !is_valid_ent(Index))
	{
		client_print(id,print_chat,"[DPRP] You are not looking at a valid door.")
		return PLUGIN_HANDLED
	}
	
	new Classname[33],Targetname[33]
	entity_get_string(Index,EV_SZ_classname,Classname,32)
	entity_get_string(Index,EV_SZ_targetname,Targetname,32)
	
	if(containi(Classname,"door") == -1)
	{
		client_print(id,print_chat,"[DPRP] You are not looking at a valid door.")
		return PLUGIN_HANDLED
	}
	
	if(DPRP_ValidDoorName(Targetname,Index))
	{
		client_print(id,print_chat,"[DPRP] This property is already in the database.")
		return PLUGIN_HANDLED
	}
	
	new Arg[33]
	read_argv(1,Arg,32)
	
	if(!DPRP_ValidPropertyName(Arg))
	{
		client_print(id,print_chat,"Property ^"%s^" does not exist.",Arg)
		return PLUGIN_HANDLED
	}
	
	DPRP_AddDoor(Targetname[1] ? Targetname : "",Targetname[1] ? 0 : Index,Arg)
	
	client_print(id,print_console,"You have added %s to the list of doors.",Targetname)
	
	return PLUGIN_HANDLED
}

public CmdSay(id)
{
	new Args[256]
	read_args(Args,255)
	
	remove_quotes(Args)
	trim(Args)
	
	if(equali(Args,"/sell",5))
	{
		new Index,Body,Targetname[33]
		get_user_aiming(id,Index,Body,200)
		
		if(!Index)
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a property.")
			return PLUGIN_HANDLED
		}
		
		entity_get_string(Index,EV_SZ_targetname,Targetname,32)
		if(!DPRP_ValidDoorName(Targetname,Index))
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a property.")
			return PLUGIN_HANDLED
		}
		
		new Property = DPRP_PropertyMatch(Targetname,Index)
		if(!Property)
			return PLUGIN_HANDLED
		
		new StrPrice[64],Temp[2]
		
		parse(Args,Temp,1,StrPrice,63)
		new Price = str_to_num(StrPrice)
		
		if(Price < 0)
		{
			client_print(id,print_chat,"[DPRP] You cannot set a property's price to a negative value.")
			return PLUGIN_HANDLED
		}
		
		if(Price)
			client_print(id,print_chat,"[DPRP] You have put this property for sale at $%d.",Price)
		else
			client_print(id,print_chat,"[DPRP] You have taken this property down from sale.")
		
		DPRP_PropertySetPrice(Property,Price)
		
		return PLUGIN_HANDLED
	}
	else if(equali(Args,"/lock",5))
	{
		new Index,Body,Targetname[33]
		get_user_aiming(id,Index,Body,200)
		
		if(!Index)
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a property.")
			return PLUGIN_HANDLED
		}
		
		entity_get_string(Index,EV_SZ_targetname,Targetname,32)
		if(!DPRP_ValidDoorName(Targetname,Index))
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a property.")
			return PLUGIN_HANDLED
		}
		
		new Property = DPRP_PropertyMatch(Targetname,Index)
		if(!Property)
			return PLUGIN_HANDLED
		
		if(DPRP_PropertyGetOwner(Property) != id)
		{
			client_print(id,print_chat,"[DPRP] You are not the owner of this property.")
			return PLUGIN_HANDLED
		}
		
		new Num = DPRP_PropertyGetLocked(Property) ? 0 : 1
		DPRP_PropertySetLocked(Property,Num)
		
		client_print(id,print_chat,"[DPRP] You have %locked the door.",Num ? "" : "un")
		
		return PLUGIN_HANDLED
	}		
	else if(equali(Args,"/changename",11))
	{
		new Index,Body,Targetname[33]
		get_user_aiming(id,Index,Body,200)
		
		if(!Index)
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a property.")
			return PLUGIN_HANDLED
		}
		
		entity_get_string(Index,EV_SZ_targetname,Targetname,32)
		if(!DPRP_ValidDoorName(Targetname,Index))
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a property.")
			return PLUGIN_HANDLED
		}
		
		new Property = DPRP_PropertyMatch(Targetname,Index)
		if(!Property)
			return PLUGIN_HANDLED
		
		if(DPRP_PropertyGetOwner(Property) != id)
		{
			client_print(id,print_chat,"[DPRP] You are not the owner of this property.")
			return PLUGIN_HANDLED
		}
		
		new Name[33],Temp[2]		
		parse(Args,Temp,1,Name,32)
		
		remove_quotes(Name)
		trim(Name)
		
		DPRP_PropertySetExternalName(Property,Name)
		
		return PLUGIN_HANDLED
	}
	else if(equali(Args,"/changeowner",12))
	{
		new Index,Body,Targetname[33]
		get_user_aiming(id,Index,Body,200)
		
		if(!Index)
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a property.")
			return PLUGIN_HANDLED
		}
		
		entity_get_string(Index,EV_SZ_targetname,Targetname,32)
		if(!DPRP_ValidDoorName(Targetname,Index))
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a property.")
			return PLUGIN_HANDLED
		}
		
		new Property = DPRP_PropertyMatch(Targetname,Index)
		if(!Property)
			return PLUGIN_HANDLED
		
		if(DPRP_PropertyGetOwner(Property) != id)
		{
			client_print(id,print_chat,"[DPRP] You are not the owner of this property.")
			return PLUGIN_HANDLED
		}
		
		new Name[33],Temp[2]		
		parse(Args,Temp,1,Name,32)
		
		remove_quotes(Name)
		trim(Name)
		
		DPRP_PropertySetOwnerName(Property,Name)
		
		return PLUGIN_HANDLED
	}
	else if(equali(Args,"/givemoney",10))
	{
		new Index,Body
		get_user_aiming(id,Index,Body,200)
		
		if(!Index || !is_user_alive(Index))
		{
			client_print(id,print_chat,"[DPRP] You are not looking at another player.")
			return PLUGIN_HANDLED
		}
		
		new Temp[33]
		parse(Args,Args,255,Temp,32)
		
		new Amount = str_to_num(Temp)
		if(Amount <= 0)
		{
			client_print(id,print_chat,"[DPRP] You did not specify a valid amount.")
			return PLUGIN_HANDLED
		}
		
		new Money = DPRP_GetUserWallet(id)
		if(Amount > Money)
		{
			client_print(id,print_chat,"[DPRP] You do not have enough money in your wallet.")
			return PLUGIN_HANDLED
		}
		
		DPRP_SetUserWallet(id,Money - Amount)
		DPRP_SetUserWallet(Index,DPRP_GetUserWallet(Index) + Amount)
		
		new Name[33]
		get_user_name(id,Name,32)
		client_print(Index,print_chat,"[DPRP] %s has given you $%d.",Name,Amount)
		
		get_user_name(Index,Name,32)
		client_print(id,print_chat,"[DPRP] You have given %s $%d.",Name,Amount)
		
		return PLUGIN_HANDLED
	}
	else if(equali(Args,"/addaccess",10))
	{
		new Index,Body,Targetname[33]
		get_user_aiming(id,Index,Body,200)
		
		if(!Index)
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a valid property.")
			return PLUGIN_HANDLED
		}
		
		entity_get_string(Index,EV_SZ_targetname,Targetname,32)
		if(!DPRP_ValidDoorName(Targetname,Index))
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a property.")
			return PLUGIN_HANDLED
		}
		
		new Property = DPRP_PropertyMatch(Targetname,Index)
		if(!Property)
			return PLUGIN_HANDLED
		
		if(DPRP_PropertyGetOwner(Property) != id)
		{
			client_print(id,print_chat,"[DPRP] You are not the owner of this property.")
			return PLUGIN_HANDLED
		}
		
		new Arg[33]
		parse(Args,Args,1,Arg,32)
		
		remove_quotes(Arg)
		trim(Arg)
		
		new Target = cmd_target(id,Arg,0)
		
		if(!is_user_connected(Target))
		{
			client_print(id,print_chat,"[DPRP] Could not find a user matching parameters.")
			return PLUGIN_HANDLED
		}
		
		if(Target == id)
		{
			client_print(id,print_chat,"[DPRP] You cannot give yourself access to a property you already own.")
			return PLUGIN_HANDLED
		}
		
		DPRP_GiveKey(Property,Target)
		
		new Name[33]
		get_user_name(Target,Name,32)
		client_print(id,print_chat,"[DPRP] You have given %s access to this property.",Name)
		
		return PLUGIN_HANDLED
	}
	else if(equali(Args,"/delaccess",10))
	{
		new Index,Body,Targetname[33]
		get_user_aiming(id,Index,Body,200)
		
		if(!Index)
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a valid property.")
			return PLUGIN_HANDLED
		}
		
		entity_get_string(Index,EV_SZ_targetname,Targetname,32)
		if(!DPRP_ValidDoorName(Targetname,Index))
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a property.")
			return PLUGIN_HANDLED
		}
		
		new Property = DPRP_PropertyMatch(Targetname,Index)
		if(!Property)
			return PLUGIN_HANDLED
		
		if(DPRP_PropertyGetOwner(Property) != id)
		{
			client_print(id,print_chat,"[DPRP] You are not the owner of this property.")
			return PLUGIN_HANDLED
		}
		
		new Arg[33]
		parse(Args,Args,1,Arg,32)
		
		remove_quotes(Arg)
		trim(Arg)
		
		new Target = cmd_target(id,Arg,0)
		
		if(!is_user_connected(Target))
		{
			client_print(id,print_chat,"[DPRP] Could not find a user matching parameters.")
			return PLUGIN_HANDLED
		}
		
		if(Target == id)
		{
			client_print(id,print_chat,"[DPRP] You cannot take away access from yourself to a property you already own.")
			return PLUGIN_HANDLED
		}
		
		DPRP_TakeKey(Property,Target)
		
		new Name[33]
		get_user_name(Target,Name,32)
		client_print(id,print_chat,"[DPRP] You have revoked %s's access to this property.",Name)
		
		return PLUGIN_HANDLED
	}
	else if(equali(Args,"/fine",5))
	{
		if(!DPRP_IsCop(id))
		{
			client_print(id,print_chat,"[DPRP] You have no access to this command.")
			return PLUGIN_HANDLED
		}
		
		new Arg[33],Amount,Index,Body
		get_user_aiming(id,Index,Body,200)
		
		if(!Index || !is_user_alive(Index))
		{
			client_print(id,print_chat,"[DPRP] You are not looking at a valid player.")
			return PLUGIN_HANDLED
		}
		
		parse(Args,Args,1,Arg,32)
		Amount = str_to_num(Arg)
		
		if(Amount < 1)
		{
			client_print(id,print_chat,"[DPRP] You must fine a valid amount of money.")
			return PLUGIN_HANDLED
		}
		
		if(Amount > DPRP_GetUserBank(Index) + DPRP_GetUserWallet(Index))
		{
			client_print(id,print_chat,"[DPRP] That user does not have enough money.")
			return PLUGIN_HANDLED
		}
		
		g_Finer[Index] = id
		g_Amount[Index] = Amount
		
		new Tmp[256]
		format(Tmp,255,"DeepPurpleRP Fine Menu^n^nAmount: $%d^n^n1. Pay^n2. Refuse",Amount)
		
		show_menu(Index,(1<<0|1<<1),Tmp,-1,g_FineMenu)
		
		client_print(id,print_chat,"[DPRP] You have sent a fine order.")
		
		return PLUGIN_HANDLED
	}
	
	return PLUGIN_CONTINUE
}

public FineHandle(id,Key)
{
	new Name[33]
	
	if(Key)
	{
		get_user_name(id,Name,32)
		client_print(g_Finer[id],print_chat,"[DPRP] %s has refused to pay the fine.",Name)
		
		client_print(id,print_chat,"[DPRP] You have refused to pay the fine.")
	}
	else
	{
		new Amount = g_Amount[id],Wallet = DPRP_GetUserWallet(id),CashLeft = Wallet - Amount
		if(CashLeft < 0)
		{
			DPRP_SetUserWallet(id,0)
			CashLeft = abs(CashLeft)
		}
		else
		{
			DPRP_SetUserWallet(id,CashLeft)
			PrintPay(id,g_Finer[id],Name)
			return
		}
		
		new Bank = DPRP_GetUserBank(id)
		Bank -= CashLeft
		
		DPRP_SetUserBank(id,Bank)
		
		PrintPay(id,g_Finer[id],Name)
	}
}

PrintPay(id,Finer,Name[33])
{
	get_user_name(id,Name,32)
	client_print(Finer,print_chat,"[DPRP] %s has paid your fine.",Name)
	
	client_print(id,print_chat,"[DPRP] You have paid the fine.")
}

public CmdSetMoney(id,level,cid)
{
	if(!DPRP_CmdAccess(id,cid,3))
		return PLUGIN_HANDLED
	
	new Arg[32],Money,Target
	read_argv(2,Arg,31)
	Money = str_to_num(Arg)
	read_argv(1,Arg,31)
	
	Target = cmd_target(id,Arg,3)
	if(!Target)
		return PLUGIN_HANDLED
		
	new Name[33]
	get_user_name(Target,Name,32)
	
	client_print(id,print_console,"You have set %s's wallet money to $%d.",Name,Money)
	
	DPRP_SetUserWallet(Target,Money)
	
	return PLUGIN_HANDLED
}

public CmdSetBank(id,level,cid)
{
	if(!DPRP_CmdAccess(id,cid,3))
		return PLUGIN_HANDLED
	
	new Arg[32],Money,Target
	read_argv(2,Arg,31)
	Money = str_to_num(Arg)
	read_argv(1,Arg,31)
	
	Target = cmd_target(id,Arg,3)
	if(!Target)
		return PLUGIN_HANDLED
		
	new Name[33]
	get_user_name(Target,Name,32)
	
	DPRP_SetUserBank(Target,Money)
	
	client_print(id,print_console,"You have set %s's bank money to $%d.",Name,Money)
	
	return PLUGIN_HANDLED
}

public CmdAddItems(id,level,cid)
{
	if(!DPRP_CmdAccess(id,cid,4))
		return PLUGIN_HANDLED
	
	new Arg[32],ItemId,Amount,Results[2],Num
	read_argv(2,Arg,31)
	
	is_str_num(Arg) ? (ItemId = str_to_num(Arg)) : (Num = DPRP_FindItemId(Arg,Results,2))
	if(Num > 1)
	{
		client_print(id,print_console,"Found more than one item with that name.")
		return PLUGIN_HANDLED
	}
	else if(!ItemId && !Num)
	{
		client_print(id,print_console,"No items with matching name/itemid found.")
		return PLUGIN_HANDLED
	}
	
	if(!ItemId)
		ItemId = Results[0]
	
	read_argv(3,Arg,31)
	Amount = str_to_num(Arg)
	read_argv(1,Arg,31)
	
	new Target = cmd_target(id,Arg,3)
	if(!Target || !ItemId || !DPRP_ValidItemId(ItemId))
		return PLUGIN_HANDLED
	
	new OldNum = DPRP_GetUserItemNum(Target,ItemId)
	if(OldNum + Amount < 0)
	{
		Amount = -OldNum
		client_print(id,print_console,"This value is too low. Set to %d to compensate.",Amount)
	}
	
	DPRP_SetUserItemNum(Target,ItemId,Num = OldNum + Amount)
	
	new ItemName[33],Name[33]
	DPRP_GetItemName(ItemId,ItemName,32)
	get_user_name(Target,Name,32)
	
	client_print(id,print_console,"Item %s for user %s set to %d (was %d).",ItemName,Name,Num,OldNum)
	
	return PLUGIN_HANDLED
}

public CmdSetJob(id,level,cid)
{	
	if(!DPRP_CmdAccess(id,cid,3))
		return PLUGIN_HANDLED
	
	new Arg[33]
	read_argv(2,Arg,32)
	new JobID = str_to_num(Arg),Results[2]
	
	if(!JobID)
	{
		new Num = DPRP_FindJobId(Arg,Results,2)
		if(Num > 1)
		{
			client_print(id,print_console,"Found more than one result for your input (%s).",Arg)
			return PLUGIN_HANDLED
		}
		
		JobID = Results[0]
	}
	
	if(!JobID || !DPRP_ValidJobId(JobID))
	{
		client_print(id,print_console,"Could not find a job id matching what you said.")
		return PLUGIN_HANDLED
	}
	
	read_argv(1,Arg,32)
	new Target = cmd_target(id,Arg,1|2)
	if(!Target)
		return PLUGIN_HANDLED
	
	DPRP_SetUserJobId(Target,JobID)
	
	new Name[33],JobName[33]
	DPRP_GetJobName(JobID,JobName,32)
	get_user_name(Target,Name,32)
	
	client_print(id,print_console,"You have set %s's job id to %d (%s).",Name,JobID,JobName)
	
	return PLUGIN_HANDLED
}	

public CmdEmploy(id,level,cid)
{
	if(read_argc() != 3)
		return DPRP_CmdAccess(id,cid,9999) + 1
	
	new Arg[33]
	read_argv(2,Arg,32)
	
	new Results[2],Result
	
	if((Result = DPRP_FindJobId(Arg,Results,2)) > 1)
	{
		client_print(id,print_console,"There is more than one job matching your input.")
		return PLUGIN_HANDLED
	}
	
	new JobID = Results[0]
	
	if(!Result)
		JobID = str_to_num(Arg)
	
	if(!JobID || !DPRP_ValidJobId(JobID))
	{
		client_print(id,print_console,"Could not find a job id matching what you said.")
		return PLUGIN_HANDLED
	}
	
	if(!DPRP_JobAccess(id,JobID) && !(DPRP_GetUserJobRight(id) & DPRP_AdminAccess()) && !(DPRP_GetUserAccess(id) & DPRP_AdminAccess()))
	{
		client_print(id,print_chat,"You have no access to this command.")
		return PLUGIN_HANDLED
	}
	
	read_argv(1,Arg,32)
	new Target = cmd_target(id,Arg)
	if(!Target)
		return PLUGIN_HANDLED
	
	new Menu[256],Salary = DPRP_GetJobSalary(JobID),Name[33],JobName[33]
	DPRP_GetJobName(JobID,JobName,32)
	get_user_name(id,Name,32)
	
	format(Menu,255,"DeepPurpleRP Employment Offer^n^n%s has offered you^na job:^n^nName: %s^nSalary: $%d/h^n^n1. Accept^n2. Decline",Name,JobName,Salary)
	
	g_JobID[Target] = JobID
	g_Employer[Target] = id
	
	show_menu(Target,MENU_KEY_1|MENU_KEY_2,Menu,-1,g_EmployMenu)
	
	return PLUGIN_HANDLED
}

public EmployHandle(id,Key)
{
	new Name[33]
	get_user_name(id,Name,32)
	
	if(!Key)
	{
		client_print(g_Employer[id],print_chat,"[DPRP] %s has accepted your job offer.",Name)
		client_print(id,print_chat,"[DPRP] You have accepted the job offer.")
		
		DPRP_SetUserJobId(id,g_JobID[id])
	}
	else
	{
		client_print(g_Employer[id],print_chat,"[DPRP] %s has declined your job offer.",Name)
		client_print(id,print_chat,"[DPRP] You have declined the job offer.")
	}
}

/*HasAccess(id,args)
{
	new StrAccess[27]
	get_pcvar_string(p_Access,StrAccess,26)
	
	new Access = DPRP_AccessToInt(StrAccess)
	
	if(read_argc() != args || !(DPRP_GetUserAccess(id) & Access))
		return FAILED
		
	return SUCCEEDED
}*/
